﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Function;
using Model;

namespace UI.AjxaFiles
{
    /// <summary>
    /// ChangePassword 的摘要说明
    /// </summary>
    public class ChangePassword : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            meseege msg = new meseege();

            string oldpwd = context.Request.QueryString["oldpwd"] ?? "";
            string newpwd = context.Request.QueryString["newpwd"] ?? "";

            ST_InvestorBLL investorbll = new ST_InvestorBLL();

            ST_Investor model = investorbll.GetModel(Method.CurrentUserID);

            if (model.LoginPw != Method.GetMD5(oldpwd, Function.Method.MD5EncryptBit.bit32))
            {
                msg.ok = false;
                msg.message = "旧密码输入错误";
            }
            else {
                model.LoginPw = Method.GetMD5(newpwd, Function.Method.MD5EncryptBit.bit32);
                model.LoginPWChanged = 2;
                if (investorbll.Update(model))
                {
                    msg.ok = true;
                    msg.message = "密码修改成功";
                }
                else {
                    msg.ok = false;
                    msg.message = "密码修改失败";
                }
            }
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(msg));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    public class meseege
    {
        bool _ok;

        public bool ok
        {
            get { return _ok; }
            set { _ok = value; }
        }


        string _message;

        public string message
        {
            get { return _message; }
            set { _message = value; }
        }
    }
}